package com.sudu.dao;

import com.sudu.domain.Comment;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface CommentDao {

    //添加一个评论
    @Insert(" insert into t_comment " +
            "(user_id ,content,create_time,video_id,parent_id)" +
            " values (#{userId},#{content},#{createTime},#{videoId},#{parentId});")
    int saveComment(Comment comment);

    //查询父级评论
    @Select("select *" +
            "        from t_comment " +
            "        where parent_id = #{ParentId} and video_id = #{videoId} " +
            "        order by create_time desc")
    List<Comment> findByParentIdNull( int ParentId , int videoId);

    //查询一级回复
    @Select(" select *" +
            "        from t_comment" +
            "        where parent_id = #{id} and video_id = #{videoId} and is_delete = 1 " +
            "        order by create_time desc")
    List<Comment> findByParentIdNotNull( int id , int videoId);

    //查询二级以及所有子集回复
    @Select(" select *" +
            "        from t_comment" +
            "        where parent_id = #{childId} and video_id = #{videoId} and is_delete = 1" +
            "        order by create_time desc")
    List<Comment> findByReplayId( int childId , int videoId);

    // 删除父评论

    @Update("update t_comment set is_delete = 0 where com_id = #{cid} and is_delete = 1")
    int deleteFaCom(int cid) ;

    @Update("update t_comment set is_delete = 0 where com_id = #{cid} and is_delete = 1")
    int deleteChildCom(int cid) ;

}
